import { app, IpcMainEvent } from "electron"

import mainWindow from "../../window/main-window"
import shell from "../../elect-api/shell"
import loginWindow from "../../window/login"
import { MIpcRequest } from "@/common/com-interface"


let cacheMap = new Map()

/**
 * 窗口启动后 初始化template
 */
app.whenReady().then(() => {
    cacheMap.set(mainWindow.id, mainWindow)
    cacheMap.set(shell.id, shell)
    cacheMap.set(loginWindow.id, loginWindow)
})


export const handleRendererSend = (event: IpcMainEvent, request:MIpcRequest) => {
    console.log("callback =======>", request)
    const { mId, func, params } = request
    if (cacheMap.has(mId)) {
        const template = cacheMap.get(mId)
        template.handleRendererSend(mId, func, params, event)
    } else {
        console.log("module: %s  not find",request.mId)
    }
}
